package org.csu.mypetstore.web.servlets;

import org.csu.mypetstore.domain.Account;
import org.csu.mypetstore.service.AccountService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/usernameIsExist")
public class usernameIsExist extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String username = req.getParameter("username");
        AccountService service = new AccountService();
        boolean result = service.is_exit(username);
        resp.setContentType("text/xml");
        PrintWriter out = resp.getWriter();
        if (result){
            out.println("<msg>Exist</msg>");
            System.out.println("1111");
        }else{
            out.println("<msg>Not Exist</msg>");
            System.out.println("222");
        }
        out.flush();
        out.close();
    }
}
